package com.javachmapi.springbootjdbctemplatemultipledatasources.controller;

import com.javachmapi.springbootjdbctemplatemultipledatasources.entity.User;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户表(User)表控制层
 * @author 宋利军
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource(name = "jdbcTemplateOne")
    private JdbcTemplate jdbcTemplateOne;

    @Resource(name = "jdbcTemplateTow")
    private JdbcTemplate jdbcTemplateTow;

    /**
     * 查询one和tow上的所有数据
     */
    @GetMapping("/all")
    public void findOneAndTowAll() {
        List<User> users1 = jdbcTemplateOne.query("select * from user",new BeanPropertyRowMapper<>(User.class));
        List<User> users2 = jdbcTemplateTow.query("select * from user",new BeanPropertyRowMapper<>(User.class));
        System.out.println("users1:"+users1);
        System.out.println("users2:"+users2);
    }
}